package la.bbs558.aop.delay;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.io.Serializable;

/**
 * @Classname DelayUserHandler
 * @Description TODO
 * @Date 2023/11/11 17:37
 * @Created by weihanmin
 */
@Component
@Slf4j
public class DefaultDelayHandler implements DelayHandler{
    @Override
    public void doHandle(DelayTask<?> delayTask, DelayQueueManager delayQueueManager) {
        Serializable entity = delayTask.getEntity();
        log.info("执行延时任务：taskEntityClass={},taskEntityJson={},retry={},handler={}", entity.getClass(), JSON.toJSONString(entity),delayTask.getRetry(),delayTask.getDelayHandler().getClass());
    }

    @Override
    public void doHandleError(DelayTask<?> delayTask, DelayQueueManager delayQueueManager, Throwable e) {
        Serializable entity = delayTask.getEntity();
        log.info("执行延时任务异常：taskEntityClass={},taskEntityJson={},retry={},handler={}", entity.getClass(), JSON.toJSONString(entity),delayTask.getRetry(),delayTask.getDelayHandler().getClass());
        log.error("执行延时任务异常：",e);
    }
}
